package common; /**
 * @Author Qiqi
 * @Date 2020/11/16 17:19
 */

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

/**
 * 一个页面的所有元素定位都在此类进行封装
 * 1、进入通讯录
 * 2、添加部门
 *  2.1 修改部门
 *  2.2 删除部门
 *  2.3 搜索部门
 * 3、添加成员
 *   3.1修改成员
 *   3.2删除成员
 *   3.3搜素成员
 */
public class ContactPage extends BasePage{
    private By parterInfo=By.cssSelector(".js_party_info");

    public ContactPage(WebDriver webDriver){
        super(webDriver);
    }

    public String searchContent(String name) throws Exception{
        senkey(By.id("memberSearchInput"),name);
        Thread.sleep(3000);
        String searchResult = webDriver.findElement(By.xpath("//*[@class='member_colLeft_cntWrap']")).getText();
        return searchResult;
    }

    public void addDepartment(String department,String departName) throws Exception{
        click(By.linkText("添加"));
        click(By.linkText("添加部门"));
        senkey(By.name("name"),departName);
        click(By.linkText("选择所属部门"));
        webDriver.findElements(By.linkText(department)).get(1).click();
        click(By.linkText("确定"));

    }
    public void updateDepartment(){

    }
    public void delDepartment(String departName){
        click(By.linkText(departName));
        click(By.xpath("//a[text()='PO测试_qq']/span"));
        click(By.linkText("删除"));
        click(By.linkText("确定"));

    }

    public void delMember(String departName) throws Exception{
        Thread.sleep(3000);
        click(By.linkText(departName));
        webDriver.findElements(By.id("member_list")).get(0).click();
        click(By.linkText("删除"));
        click(By.linkText("确认"));
    }

    public void addMember(String userName,String acctid,String phone) throws Exception{
        click(By.linkText("PO测试_qq"));
        Thread.sleep(3000);
        click(By.linkText("添加成员"));
        senkey(By.name("username"),userName);
        senkey(By.name("acctid"),acctid);
        senkey(By.name("mobile"),phone);
        click(By.linkText("保存"));
    }
    public void updateMember(){

    }



    public String getPartyInfo(){
        //
        String content = webDriver.findElement(parterInfo).getText();
        System.out.println(content);
        return content;
    }

    public void clearMemberSearchInput(){
        click(By.id("clearMemberSearchInput"));
    }

}
